/**
 * 
 */
package mt.filter;

import static org.junit.Assert.*;

import java.util.ArrayList;

import mt.Order;
import mt.comm.ServerSideMessage;
import mt.comm.ServerSideMessage.Type;
import mt.dummy.MicroTraderServerDummy;
import mt.dummy.ServerCommDummy;
import mt.dummy.ServerSideMessageExample;
import mt.server.MicroTraderServer;

import org.junit.Test;

/**
 * @author utilizadorrj
 *
 */
public class AnalyticsFilterTest {

	
	
	/**
	 * Test method for {@link mt.filter.AnalyticsFilter#getNextMessage()}.
	 */
	@Test
	public void testGetNextMessage() {
		//Codigo apenas para testes a partir do main
		ServerCommDummy serverComm = new ServerCommDummy();
		serverComm.start();
		//data generation
		ArrayList<ServerSideMessage> messageList=new ArrayList<ServerSideMessage>();
		Order order = null;
		System.out.println("Server CommDummyStarted");
		
		for (int i=0;i<20;i++){
			ServerSideMessageExample message = new ServerSideMessageExample (("mailClient"+i+"@mail.mail"),Type.DISCONNECTED,null);
			messageList.add(message);
			
		}
		for (int i=0;i<20;i++){
			ServerSideMessageExample message = new ServerSideMessageExample (("mailClient"+i+"@mail.mail"),Type.CONNECTED,null);
			messageList.add(message);
			
		}
		
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order1=order.createBuyOrder(nickname, "xpto", 10, 200.0);
			ServerSideMessageExample message = new ServerSideMessageExample (nickname,Type.NEW_ORDER,order1);
			System.out.println(message.getOrder().toString());
			messageList.add(message);
			
		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMessageExample message = new ServerSideMessageExample (nickname,Type.NEW_ORDER,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);
			
		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMessageExample message = new ServerSideMessageExample (nickname,Type.NEW_ORDER,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);
			
		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMessageExample message = new ServerSideMessageExample (nickname,Type.NEW_ORDER,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);
			
		}
		for (int i=10;i<20;i++){
			ServerSideMessageExample message = new ServerSideMessageExample (("mailClient"+i+"@mail.mail"),Type.CONNECTED,null);
			messageList.add(message);
			
		}
		assertNotNull(messageList);
		assertNotNull(serverComm);
		serverComm.loadDataForTesting(messageList);
		AnalyticsFilter filter = new AnalyticsFilter(serverComm);
		MicroTraderServer  server     = new MicroTraderServerDummy();
		assertNotNull(filter);
		assertNotNull(server);
		server.start(filter);
		
		
		
	}

	
}
